import { HelpArticle } from "@/type/helpArticleManage";
import { LazyTableService, BaseAuthApi } from "@/hooks/useLazyLable";
import axios, { Response, CancelToken, authGuard } from "./axios";
import factorySingleClass from "./SingleClass";

interface HelpArticleManageService extends BaseAuthApi {
    EDIT: string;
    DETAIL: string;
}

let cancel: any;
class HelpArticleManageService extends LazyTableService {
    @authGuard
    add(obj: HelpArticle) {
        return axios.post<any>(`/mediaslib-service/content/add`, obj);
    }
    @authGuard
    edit(obj: HelpArticle) {
        return axios.post<any>(`/mediaslib-service/content/edit`, obj);
    }
    @authGuard
    getList(obj: any = {}) {
        cancel && cancel();
        return axios.post<Response<HelpArticle>>(
            `/mediaslib-service/content/getList`,
            obj,
            {
                cancelToken: new CancelToken((c) => (cancel = c)),
            },
        );
    }
    @authGuard
    remove(id: string) {
        return axios.delete<Response<any>>(
            `/mediaslib-service/content/del?id=${id}`,
        );
    }
    @authGuard
    detail(id: string) {
        return axios.get<Response<HelpArticle>>(
            `/mediaslib-service/content/detail?id=${id}`,
        );
    }
}

export default factorySingleClass(HelpArticleManageService);
